package msu.erdc.hci;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

import msu.erdc.hci.DateDialogFragment.DateDialogFragmentListener;
import msu.erdc.hci.customObjects.AccidentObject;
import msu.erdc.hci.customObjects.DamageReportObject;
import msu.erdc.hci.customObjects.InsuranceObject;
import msu.erdc.hci.customObjects.VehicleObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import java.util.Date;
import java.text.DateFormat;

public class DamageReport extends Fragment{
	
	ArrayList<DamageReportObject> damageReport;
	int accidentIndex;
	int vehicleIndex;
	TextView breadCrumb;
	TextView selectedArea;
	
	private Button mediaDRButton;
	private ImageButton frontImageButton;
	private ImageButton backImageButton;
	private ImageButton topImageButton;
	private ImageButton rightImageButton;
	private ImageButton leftImageButton;
	private ImageView focusImageView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View view =  inflater.inflate(R.layout.damage_report, container, false);
		final FragmentManager manager = getFragmentManager();
		
		selectedArea = (TextView) view.findViewById(R.id.selectedAreaDRTextView);
		
		breadCrumb = (TextView) view.findViewById(R.id.breadcrumbDRTextView);
		breadCrumb.setText(((Global)getActivity().getApplication()).accidents.get(accidentIndex).toString() + "/" + 
		((Global)getActivity().getApplication()).accidents.get(accidentIndex).reportItemList.vehicleList.get(vehicleIndex).year + " " +
		((Global)getActivity().getApplication()).accidents.get(accidentIndex).reportItemList.vehicleList.get(vehicleIndex).make + " " +
		((Global)getActivity().getApplication()).accidents.get(accidentIndex).reportItemList.vehicleList.get(vehicleIndex).model + "/Damage Report:");
		
		mediaDRButton = (Button) view.findViewById(R.id.mediaDRButton);
		frontImageButton = (ImageButton) view.findViewById(R.id.frontImageButton);
		backImageButton = (ImageButton) view.findViewById(R.id.backImageButton);
		topImageButton = (ImageButton) view.findViewById(R.id.topImageButton);
		rightImageButton = (ImageButton) view.findViewById(R.id.rightImageButton);
		leftImageButton = (ImageButton) view.findViewById(R.id.leftImageButton);
		focusImageView = (ImageView) view.findViewById(R.id.focusImageView);
		
		mediaDRButton.setOnClickListener(unsupportedClick);
		focusImageView.setOnClickListener(unsupportedClick);
		
		frontImageButton.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				focusImageView.setImageResource(R.drawable.front);
				selectedArea.setText("Front");
			}});
		backImageButton.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				focusImageView.setImageResource(R.drawable.back);
				selectedArea.setText("Back");
			}});
		topImageButton.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				focusImageView.setImageResource(R.drawable.top);
				selectedArea.setText("Top");
			}});
		rightImageButton.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				focusImageView.setImageResource(R.drawable.right_side);
				selectedArea.setText("Right Side");
			}});
		leftImageButton.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				focusImageView.setImageResource(R.drawable.left_side);
				selectedArea.setText("Left Side");
			}});
		
		return view;
	}
	
	OnClickListener unsupportedClick = new OnClickListener(){

		@Override
		public void onClick(View v) {
			showUnsupportedToast();
		}};
	
	private void showUnsupportedToast()
	{
		Toast.makeText(getActivity(), "Interactivity is limited in this prototype.", Toast.LENGTH_SHORT).show();
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //do stuff here
        
        Bundle arguments = getArguments();
        if(arguments.containsKey("accidentIndex"))
        {
        	accidentIndex = arguments.getInt("accidentIndex");
        }
        if(arguments.containsKey("vehicleIndex"))
        {
        	vehicleIndex = arguments.getInt("vehicleIndex");
        }
        
        damageReport = ((Global)getActivity().getApplication()).accidents.get(accidentIndex).reportItemList.vehicleList.get(vehicleIndex).damageList;
    }


}